<template>
	<view>
		<view class="content">
			<view class="" @tap="$util.toUrl('./renzhengson')">
				<selfCode lable="实名及银行卡认证" :dongLabel="renzheng" ></selfCode>
			</view>
			<view class="" v-if="type==1" @tap="gouwuxinxi()">
				<selfCode  lable="购物信息" :dongLabel="gouwuWannshan" borderBottom="unset"></selfCode>
			</view>
			<view class="" v-if="type==2" @tap="dianpuxinx()">
				<selfCode  lable="店铺信息" :dongLabel="gouwuWannshan" borderBottom="unset"></selfCode>
			</view>
		</view>
	</view>
</template>

<script>
	import selfCode from "@/components/self-card/self-card.vue"
	export default {
		components:{
			selfCode
		},
		data() {
			return {
				type:1,
				renzheng:"未认证",
				gouwuWannshan:"已完善"
			}
		},
		onLoad() {
			var that = this;
			this.isRenzheng();
			uni.$on('renzhengson',function(data){
				console.log("事件====认证"+JSON.stringify(data));
			    if(data.renzheng==2){
					that.renzheng = "已认证";
				}  
			})
			
			uni.$on('dianopuxinxi',function(data){
				console.log("事件====店铺信息完善"+JSON.stringify(data));
			    if(data.wanshan){
					that.gouwuWannshan = "已完善";
				}else{
					that.gouwuWannshan = "未完善";
				}
			})
			
			
		},
		methods: {
			gouwuxinxi(){
				var that = this;
				 that.$util.nuiAjax(that.$jiekou.userInfo,{id:uni.getStorageSync("token")},function(res){
					if(res.result=="true"){
						that.user = res.data;
						uni.setStorageSync("userInfo",res.data);
						that.$util.toUrl('./gouwuxinxi')
					}
				})
			},
			dianpuxinx(){
				var that = this;
				 that.$util.nuiAjax(that.$jiekou.userInfo,{id:uni.getStorageSync("token")},function(res){
					if(res.result=="true"){
						that.user = res.data;
						uni.setStorageSync("userInfo",res.data);
						that.$util.toUrl('./dianpuxinxi')
					}
				})
			},
			isRenzheng:function(){
				const user = uni.getStorageSync("userInfo");
				console.log(1);
				this.type=user.type;
				if(user.attestation==2){
					this.renzheng = "认证通过";
				}else {
					this.renzheng = "未认证";
				}
				if(this.type==1){
					var iswanshan = false;
					if(user.taobaoZhanghao == undefined || user.taobaoZhanghao=="" ){
						iswanshan = true;
					}
					if(user.taobaoZhanghao == undefined || user.jingdongZhanghao==""){
						iswanshan = true;
					}
					if(user.pinduoduoZhanghao == undefined || user.pinduoduoZhanghao==""){
						iswanshan = true;
					}
					if(iswanshan){
						this.gouwuWannshan = "待完善";
					}
				}
				
				if(this.type==2){
					var iswanshan = false;
					if(user.taobaodianId == undefined || user.taobaodianId=="" ){
						iswanshan = true;
					}
					if(user.jingdongdianId == undefined || user.jingdongdianId==""){
						iswanshan = true;
					}
					if(user.pinduoduoId == undefined || user.pinduoduoId==""){
						iswanshan = true;
					}
					if(iswanshan){
						this.gouwuWannshan = "待完善";
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: $page-bg-color;
	}
	.content{
		box-shadow:0px 8px 16px 0px rgba(246,247,248,1);
		background-color: #FFFFFF;
		margin-top: 20rpx;
	}
</style>
